﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using FinApp.ViewModels;
using FinApp.ViewModels.Repositories;

namespace FinApp.Views {
    public partial class MainPage : PhoneApplicationPage {
        public MainPage() {
            InitializeComponent();

            // Establecer el contexto de datos
            this.DataContext = ViewModelFactory.Instance.GetViewModel<MainViewModel>();
            this.Loaded += new RoutedEventHandler(OnMainPageLoaded);
        }

        // Cargar datos para los elementos ViewModel
        private void OnMainPageLoaded(object sender, RoutedEventArgs e) {
            if (!ViewModelFactory.Instance.GetViewModel<MainViewModel>().IsDataLoaded) {
                ViewModelFactory.Instance.GetViewModel<MainViewModel>().LoadData();
            }
        }

    }
}